<?php

/**
 * product form.
 *
 * @package    semramode
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class productForm extends BaseproductForm
{
  public function configure()
  {

  $this->widgetSchema['product_key'] = new sfWidgetFormInputHidden();
  $this->validatorSchema['product_key'] = new sfValidatorString();
  $product_key = time();
 $this->setDefault('product_key', $product_key);
    $productPhoto = new image();
    $productPhoto->setProduct($this->getObject());

    $subform = new imageForm($productPhoto);
 
  $subform->setDefault('product_id', $product_key);
  $subform->validatorSchema['product_id'] = new sfValidatorString();
// if($this->isNew()){ ;}
 //else{
if(!$this->isNew())$this->embedRelation('images');//}

  $this->embedForm('newPhotos', $subform);
//$this->mergePostValidator(new ProductPhotoValidatorSchema()) ;


      }
 
public function saveEmbeddedForms($con = null, $forms = null)
{
if($con == null){
    $con = $this->getConnection();
}
         if (null === $forms)
  {
            

    $photos = $this->getValue('newPhotos');

    $forms = $this->embeddedForms;
   
    foreach ($this->embeddedForms as $name => $form)
    {
        
      if ($photos['filename'] == '')
      {
          
        unset($forms['newPhotos']);
  
      }
    }
         return parent::saveEmbeddedForms($con, $forms);
         
    
  }

  


    }

 

}
